#include <stdio.h>
#include <stdlib.h>

#define N_MAX  20
#define M_MAX  20
#define K_MAX 100

int transp(int array[N_MAX][M_MAX], int row, int column, int size)
{
	int tmp = 0;
	int i = 0, j = 0;
	for (i = 0 ; i < size ; ++i) {
		if (i > 0) {
			for (j = 0 ; j - i < 0 ; ++j) {
				tmp = array[i+row][j+column];
				array[i+row][j+column] = array[j+row][i+column];
				array[j+row][i+column] = tmp;
			}
		}
	}
	return 0;
}


int main(void)
{
	int arr[N_MAX][M_MAX], n = 0, m = 0;
	int k, oper[K_MAX][3], rows = 0, cols = 0; /* oper[][0] - ROW ; oper[][1] - COLUMN ; oper[][2] - SIZE */
	register int i, j;

	freopen("transpose.in", "r", stdin);
	freopen("transpose.out","w",stdout);

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; ++i)
		for (j = 0; j < m; ++j)
			scanf("%d", &arr[i][j]);
	scanf("%d", &k);
	i = 0;
	while (i < k) {
		scanf("%d%d%d", &oper[i][0], &oper[i][1], &oper[i][2]);
		++i;
	}

	i = 0;
	while (i < k) {
		transp(arr, oper[i][0], oper[i][1], oper[i][2]);
		++i;
	}

	for (i = 0 ; i < n ; ++i) {
		for (j = 0 ; j < m ; ++j)
			printf("%d ", arr[i][j]);
		putchar('\n');
	}
	return 0;
}
